
const nowTime = (new Date().getTime() / 1000);

import { ADMIN_USER, MEDICAL_USER, ORG_USER, LOCAL_USER, ZY_USER,MALL_USER } from "./const"

function getUserInfo() {

    let userInfo = localStorage.getItem(LOCAL_USER);
    if (userInfo) {
        return JSON.parse(userInfo)
    }
    return null
}

function getToken() {
    let token = null;
    let userInfo = getUserInfo();
    if (userInfo && userInfo.expire > nowTime) {
        return userInfo["token"]
    }
    return token
}

function getUserType() {
    let type = "login";
    let userInfo = getUserInfo();
    if (userInfo && userInfo.expire > nowTime) {
        return userInfo["type"]
    }
    return type
}

function typeName() {
    return {
        "ADMIN": [ADMIN_USER, "管理员"],
        "MEDICAL": [MEDICAL_USER, "药店代表"],
        "ORG": [ORG_USER, "机构代表"],
        "ZY": [ZY_USER, "中药店"],
        "MALL":[MALL_USER,"商城"]
    }
}

function log(...msg) {
    if (process.env.NODE_ENV === 'development') {
        console.log("log--", msg)
    }
}


function isMobile(text) {
    return (/^1\d{10}$/).test(text)
}

export {
    getUserInfo,
    getToken,
    getUserType,
    typeName,
    log,
    isMobile
}